﻿using System;
using EmailJabber.Logic.Commands.Base;
using EmailJabber.Logic;
using EmailJabber.Logic.Logic.BusinessLogic;

namespace FinancialPersonal.Commands
{
	public class GetStatisticCommand : CommandBase
	{
		public GetStatisticCommand()
		{
			States.States.Instance.Init();
			_aliaces =new[]{"сотcояние","отчет"};
		}
		
		protected override string GetDecription()
		{
			return "Return statistic for all goals.";
		}
		
		protected override System.Collections.Generic.List<Guid> GetTags()
		{
			var result = base.GetTags();
			result.Add(FinancialHelpCommnd.FinanceTag);
			return result;
		}

		protected override Guid GetId()
		{
			return new Guid("9FC932DD-5191-4A26-A19B-BB02B79FC531");
		}

		protected override void ExecuteSafe(MessageIM comnd)
		{
			var currentUser = Logic.FinanceLogic.Instance.GetUserByJid(comnd.From);
			if(currentUser==null)
			{
				BL.Instance.Send(MessageIM.GetReply("currentUser==null",comnd));
				return;
			}
			string messageBody = string.Empty;
			messageBody += "Ваш уникальный идентификатор " +currentUser.Id + Environment.NewLine;
			messageBody += "Зарплата " + currentUser.DateMonthlyIncome + " числа" + Environment.NewLine;
			messageBody += "Ежемесячный доход "+currentUser.MonthlyIncome.ToString("C") + Environment.NewLine;
			messageBody += "Вы тратите каждый месяц "+currentUser.SpendMoneyPerMonth.ToString("C") + Environment.NewLine;
			messageBody += "Цели: "+ Environment.NewLine;
			if(currentUser.Goals!=null)
				foreach(var goal in currentUser.Goals)
			{
				messageBody += "-- Цель номер "+goal.Id.ToString() + Environment.NewLine;
				messageBody += "-- Цель "+goal.Description + Environment.NewLine;
				messageBody += "-- Планируем закончить к "+goal.EndCollect.ToShortDateString() + Environment.NewLine;
				messageBody += "-- Сейчас денег уже "+goal.Cost.ToString("C")+ Environment.NewLine;
				messageBody += Environment.NewLine;
			}
			messageBody += "Регулярные платежи: "+ Environment.NewLine;
			if(currentUser.RepetatedPayment!=null)
				foreach(var payment in currentUser.RepetatedPayment)
			{
				messageBody += "-- Регулярный платежь номер "+payment.Id.ToString() + Environment.NewLine;
				messageBody += "-- Название "+payment.Description+ Environment.NewLine;
				messageBody += "-- Размер платежа "+payment.Value.ToString("C")+ Environment.NewLine;
				messageBody += "-- Платеж каждые "+payment.RepeatPeriod + " месяцев" + Environment.NewLine;
				messageBody += Environment.NewLine;
			}
			BL.Instance.Send(MessageIM.GetReply(messageBody,comnd));
			
		}
	}
}